package net.projecteuler.programs.program0007;

import net.projecteuler.programs.TimeLogger;

import java.util.ArrayList;
import java.util.List;

/**
 * 10001st prime
 *
 * By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
 *
 *  What is the 10 001st prime number?
 *
 * Created by zhaojjd on 2016/3/21.
 */
public class Program0007 {

    public long find(int index){
        int len = index - 1;
        long rst = 0;
        List<Long> list = new ArrayList<Long>(10000);

        long num = 2;
        while(true){
            boolean devided = false;
            for(Long factor : list){
                if(num % factor == 0){
                    devided = true;
                    break;
                }
            }
            if(!devided){
                if(list.size() < len){
                    list.add(num);
                }else {
                    rst = num;
                    break;
                }
            }
            num++;
        }
        return rst;
    }

    public static void main(String[] args) {
        Program0007 p = new Program0007();

        TimeLogger.tag();
        System.out.println("p.find(10001) = " + p.find(10001));
        TimeLogger.print();
    }

}
